package com.dfbz.demo01_类加载器;

import junit.textui.TestRunner;

import java.io.InputStream;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo02_通过类加选择器获取资源 {

    public static void main(String[] args) throws Exception {

        // 获取一个AppClassLoader
        ClassLoader classLoader = TestRunner.class.getClassLoader();

        // 获取类路径下的一个资源
        InputStream is = classLoader.getResourceAsStream("hello.txt");

        byte[] data = new byte[1024];
        int len = is.read(data);

        System.out.println("通过类加载器获取的资源: " + new String(data, 0, len));

        is.close();
    }
}
